
<?php 
	include_once("web_header.php");
?>
<script type="text/javascript"  src="/include/ajaxfileupload.js"></script>

 
<div class="web_wrap">
    <div class="reg_content_wrap">
         <div  style="width:25%;float:left;">
				<?php 
					include_once("web_coach_dashmenu.php");
				?>
         </div>
         <div class="dash_rightdiv">
        <div class="subhead"> 
               <span class="glyphicon glyphicon-picture"></span>  相册
           </div>
 
<div id="regbox">

<div style="">
       <button id="createBtn" type="button" class="btn btn-link"> <span class="glyphicon glyphicon-plus"></span> 添加照片</button>
</div>



<div id="uploadpanel" style=" background-color:#f6f6f6; margin:20px;margin-bottom:30px; display:none">
    <div class="formgroup"  style="height:130px;" >
			  <h3>上传图片</h3>
			  <div class="inputcontent">
			          <img src="/images/addimg.png" id="ablumimg" style="height:100px"> 

		            <input id="userthumbfile" name="file" type="file" accept="image/*;capture=camera" onchange="upload('userthumbfile')" style="opacity:0; height:1px; width:1px; -webkit-appearance: none;  -moz-appearance: none; appearance: none; overflow: hidden;  " >
			   </div>
	 </div>

 	  <div class="formgroup">
			     <h3>描述</h3>
			    <input  type="input" value="" name="img_desc" id="img_desc" placeholder="填写描述文字">
	 </div>

                 <div class="formgroup">
                     <h3> &nbsp; </h3>
                    <button id="submitButton" type="" class="btn btn-primary">
                       <div id="submitButtonText">添加</div>
                    </button>
                   <button id="cancelBtn" type="button" class="btn btn-link">取消</button>
                </div>

</div>
 
<ul class="dash_ablum" style="margin-top:20px;">
 

 <?php if($ablum!=''||$ablum!=null): ?>
       <?php foreach ($ablum as $img): ?>
           <li>
               <img src="<?=$img->img_src?>">
               <br>
               <?=$img->img_desc?>
           </li>
     <?php endforeach; ?>
 <?php endif; ?>
</ul>
</div>
	      
       </div>
       <div style="clear:both"></div>

     </div>
</div>


 
<script type="text/javascript">

   var userid = '';
   var phonenumber = '';
   var wx_openid = '';


   $("#createBtn").on('click',function(){
         $("#uploadpanel").slideDown();
   });

   $("#cancelBtn").on('click',function(){
         $("#uploadpanel").slideUp();
   });


   $("#ablumimg").on('click',function(){
         $("#userthumbfile").click();
   });

   $(".addcert").on('click',function(){
       var certid = $(this).attr("certid");
       if(certid='1'){
             $("#cert2div").show();
       }  
       if(certid='2'){
             $("#cert3div").show();
       }  
   });


  function upload (fileupload_id) {

	  	layer.open({
		    content: '正在上传',
		    className: 'bluelayer'
  		});
   
       //$("#uploadbg").attr("src","images/uploadbg2.png"); 
      
        $.ajaxFileUpload({
             url         :'/api_fileupload_full.php',
             secureuri   :false,
             fileElementId  : fileupload_id ,
             dataType    : 'json',
             success: function (data, status)            //相当于java中try语句块的用法
             {
                 //$("#idcard").attr("src",data.filepath);
                 $("#ablumimg").attr("src",data.filepath);

                    layer.open({
            				    content: '上传成功',
            				    className: 'bluelayer',
            				    time: 1
            				});

             },
             error: function (data, status, e)            //相当于java中catch语句块的用法
             {
                console.log(e);
                layer.open({
    				        content: '出错了!可能是网络有点慢,请尝试从手机相册中选择照片上传',
    				        tbtn: ['OK']
    				    });
                //$("#uploadbg").attr("src","images/uploadbg.png"); 
              }

         });
        return true;
   }

 
    $("#submitButton").on('click',function(){
    	   sendInfo_1();
    });

    function showlayer(showword){
			layer.open({
			    content:showword,
			    style: 'background-color:#09C1FF; color:#fff; border:none;',
			    time: 2
			});
    }

    function sendInfo_1(){

 	    var img_src = $("#ablumimg").attr("src");
      var thumb_src = "";
      var img_desc = $("#img_desc").val();

 	    layer.open({
  		    content: '正在添加',
  		    className: 'bluelayer'
  		});

        $.ajax({
            url: '/index.php/coach/web_dashboard_ablum_handle',
            type: 'POST',
            data:{img_src:img_src,thumb_src:thumb_src,img_desc:img_desc},
            dataType: 'json',
            error: function(){
                  alert('Error loading PHP document'); 
                  posting = false;
             },
            success: function(result){
 
         				if(result.result==7){   
                      layer.open({
                						    content: '请重新登录',
                						    className: 'bluelayer',
                						    time: 233
                					  });
                      return;
                 }

                if(result.result==1){
                      layer.open({
            						    content: '上传完成',
            						    className: 'bluelayer',
            						    time: 2
            						});
                     window.location.reload();

                      return;
                }else{
                      layer.open({
          						    content: '请填写完整',
          						    className: 'bluelayer',
          						    time: 2
          						});
                      return;
                }
                posting = false;
            }
        });

    }

 
 
</script>




<?php 
	include_once("web_footer.php");
?>
